package com.feiyu.auth.captcha;

import com.wf.captcha.*;
import com.wf.captcha.base.Captcha;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author tang ming
 * @since 2021/12/5 23:04
 */
public class CaptchaBuilder {
    private static final String[] type={"spec","gif"};
    public static Captcha createCaptcha(String captchaType,int with,int height,int len){
        Captcha captcha=null;
        switch (captchaType){
            case "chineseGif":
                captcha = new ChineseGifCaptcha(with,height,len);
                break;
            case "arithmetic":
                captcha = new ArithmeticCaptcha(with,height,len);
                break;
            case "chinese":
                captcha = new ChineseCaptcha(with,height,len);
                break;
            case "spec":
                captcha = new SpecCaptcha(with,height,len);
                break;
            default: captcha=new GifCaptcha(with,height,len);
        }
        return captcha;
    }
    public static Captcha randomCaptcha(int with,int height,int len){
        ThreadLocalRandom random = ThreadLocalRandom.current();
        String captchaType = type[random.nextInt(type.length)];
        return createCaptcha(captchaType,with,height,len);
    }
}
